package ke05;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileCopy {

	public void copy(String src, String dest){
		
		FileInputStream fis = null;
		FileOutputStream fos = null;
		try {
			fis = new FileInputStream(src);
			fos = new FileOutputStream(dest);
			
			int ava = fis.available();
			byte[] buffer = new byte[ava];
			int len = 0;
			while(len != -1){
				len = fis.read(buffer);
				if(len != -1){
					fos.write(buffer);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		finally{
			try {
				if(fis != null)
					fis.close();
				if(fos != null)
					fos.close();
			} catch (IOException e) {
				e.printStackTrace();
			}	
		}
	}
	
	public static void main(String[] args) {
		new FileCopy().copy("fileWriter.txt", "FileWriterCopy.txt");
	}

}
